package com.ruoyi.youtian.controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.annotation.AutoSetDefaultParams;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.youtian.domain.ScenePoint;
import com.ruoyi.youtian.domain.vo.ScenePointVo;
import com.ruoyi.youtian.service.IScenePointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 场景与点位关联Controller
 *
 * @author ruoyi
 * @date 2022-09-15
 */
@Controller
@RequestMapping("/youtian/scene-point")
public class ScenePointController extends BaseController
{
    @Autowired
    private IScenePointService scenePointService;

    /**
     * 查询场景与点位关联列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody ScenePoint scenePoint)
    {
        startPage();
        List<ScenePoint> list = scenePointService.selectScenePointList(scenePoint);
        return getDataTable(list);
    }

    /**
     * 导出场景与点位关联列表
     */
    @Log(title = "场景与点位关联", businessType = BusinessType.EXPORT)
    @ResponseBody
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScenePoint scenePoint)
    {
        List<ScenePoint> list = scenePointService.selectScenePointList(scenePoint);
        ExcelUtil<ScenePoint> util = new ExcelUtil<ScenePoint>(ScenePoint.class);
        util.exportExcel(response, list, "场景与点位关联数据");
    }

    /**
     * 获取场景与点位关联详细信息
     */
    @GetMapping(value = "/{id}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scenePointService.selectScenePointById(id));
    }

    /**
     * 新增场景与点位关联
     */
    @Log(title = "场景与点位关联", businessType = BusinessType.INSERT)
    @PostMapping
    @ResponseBody
    @AutoSetDefaultParams
    public AjaxResult add(@RequestBody ScenePointVo scenePointVo){

        // 为场景新增点位后还需新增一条场景点位上下限属性
        return toAjax(scenePointService.insertScenePoint(scenePointVo));
    }

    /**
     * 修改场景与点位关联
     */
    @Log(title = "场景与点位关联", businessType = BusinessType.UPDATE)
    @PutMapping
    @ResponseBody
    @AutoSetDefaultParams
    public AjaxResult edit(@RequestBody ScenePoint scenePoint)
    {
        return toAjax(scenePointService.updateScenePoint(scenePoint));
    }

    /**
     * 删除场景与点位关联
     */
    @Log(title = "场景与点位关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ResponseBody
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scenePointService.deleteScenePointByIds(ids));
    }


    /**
     * 场景点位解除关联
     * @param scenePoint
     * @return
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult scenePointRemove(@RequestBody ScenePoint scenePoint){
        return  AjaxResult.success(scenePointService.scenePointRemove(scenePoint));
    }

}
